package jmvcclab.View;
import jmvcclab.Model.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 *
 * @author home
 */
public class IOPanel extends JPanel implements ActionListener{
    private JTextField text;
    private JButton goButton;
    private MainData mainData;

    IOPanel(MainData m){
        super();
        mainData=m;

        text = new JTextField();
        text.setPreferredSize(new Dimension(160,25));
        this.add(text);

        goButton = new JButton("Go!");
        goButton.setPreferredSize(new Dimension(60,25));
        goButton.setBackground(Color.red);
        goButton.setForeground(Color.white);
        goButton.setBorderPainted(false);
        this.add(goButton);
        this.setVisible(true);

        goButton.addActionListener(this);
    }
    public JButton getGOButton(){
        return goButton;
    }
    public JTextField getTextField(){
        return text;
    }
    public String getText(){
        return text.getText();
    }
    public void setText(String s){
        text.setText(s);
    }
    public void addText(String s){
        String t=text.getText();
        text.setText(t+s);
    }
    public void actionPerformed(ActionEvent e){
        if(e.getSource()== goButton) {
            mainData.Query=getText();
            setText(mainData.Result.toString());
        }
    }
}
